package ink.lovejinhu.swardToOffer;

import ink.lovejinhu.common.ListNode;

/**
 * @author jinhu
 * created 2021-08-18 10:01
 */
public class Offer_052 {
    /**
     * 两个链表的公共节点
     * 最开始我用的栈
     * 你走过我来时走的路
     *
     * @param headA
     * @param headB
     * @return
     */
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode newHeadA = headA;
        ListNode newHeadB = headB;
        while (newHeadA != newHeadB) {
            newHeadA = newHeadA == null ? headB : newHeadA.next;
            newHeadB = newHeadB == null ? headA : newHeadB.next;
        }
        return newHeadA;
    }
}
